﻿/*****************************************************************//**
 * @file    FITKGraphObjectPostCut.h
 * @brief   Post graph object for cut view.
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-06-17
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTPOSTCUT_H__
#define __FITKGRAPHOBJECTPOSTCUT_H__

#include "FITKGraphObjectPostModelBase.h"

#include <vtkCommand.h>
#include <QObject>

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class QVariant;

class vtkWidgetRepresentation;
class vtkSliderWidget;
class vtkSphereWidget2;

namespace Interface
{
    class FITKAbstractViewCut;
}

namespace Exchange
{
    /**
     * @brief   The cutter's widget callback.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-07-06
     */
    class vtkCutterCallback : public vtkCommand, public QObject
    {
    public:
        /**
         * @brief   Constructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-06
         */
        vtkCutterCallback() = default;
        
        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-06
         */
        ~vtkCutterCallback() = default;

        /**
         * @brief   The call back of plane changed.[virtual][override]
         * @param   caller: The caller
         * @param   eventId: Event id
         * @param   callData: The data
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-06
         */
        virtual void Execute(vtkObject *caller, unsigned long eventId, void* callData) override;

    };

    /**
     * @brief   The slider's widget callback.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-07-08
     */
    class vtkSliderCallback : public vtkCommand, public QObject
    {
    public:
        /**
         * @brief   Constructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        vtkSliderCallback() = default;

        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        ~vtkSliderCallback() = default;

        /**
         * @brief   Set the input sphere widget.
         * @param   widget: The sphere widget
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        void setSphereWidget(vtkSphereWidget2* widget);

        /**
         * @brief   The call back of slider changed.[virtual][override]
         * @param   caller: The caller
         * @param   eventId: Event id
         * @param   callData: The data
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        virtual void Execute(vtkObject *caller, unsigned long eventId, void* callData) override;

    private:
        /**
         * @brief   The interactive sphere widget.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        vtkSphereWidget2* m_sphereWidget2{ nullptr };
    };

    /**
     * @brief   Post graph object for cut view.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-06-17
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectPostCut : public FITKGraphObjectPostModelBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectPostCut, FITKGraphObjectPostModelBase);
        FITKCLASS(Exchange, FITKGraphObjectPostCut);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data( If the post data is import with file, the case data maybe nullptr)
         * @param   cutData: The input cut view's post data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-17
         */
        FITKGraphObjectPostCut(AbaqusData::FITKDataCase* caseData, Interface::FITKAbstractViewCut* cutData);

        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-17
         */
        ~FITKGraphObjectPostCut();

        /**
         * @brief   Show or hide the cut widget.
         * @param   flag: Show or hide
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-06
         */
        void setWidgetVisible(bool flag);

        /**
         * @brief   Update the actors.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-17
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Get the visibility from the data object.[override]
         * @return  The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-06
         */
        bool getDataVisibility() override;

        /**
         * @brief   Get the fixed sized bounds of this graph object.[override]
         * @param   The bounds size
         * @return  If the graph object has fixed sized bounds
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        bool getFixedBounds(double* bounds) override;

        /**
         * @brief   Set if the graph object can be picked.[override]
         * @param   isPickable: Pickable
         * @param   dim: The dimision of the pickable object( -1 means the whole graph object )[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-11
         */
        void setPickable(bool isPickable, int dim = -1) override;

        /**
         * @brief   Get the algorithm output port for calculation.[override]
         * @param   forRendering: The output type[default]
         * @return  The output port
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-22
         */
        vtkAlgorithmOutput* getOutputPort(bool forRendering = false) override;

        /**
         * @brief   Get the algorithm output dataset for calculation or visualization.[override]
         * @param   forRendering: The output type[default]
         * @return  The output dataset
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-22
         */
        vtkDataSet* getOutput(bool forRendering = false) override;

        /**
         * @brief   Get the feature data of the post model.[override]
         * @return  The mesh feature
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-22
         */
        Interface::FITKMeshFeatureVTK* getMeshFeature() override;

    private:
        /**
         * @brief   Initialize the interactive widget for cutter.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-05
         */
        void initWidgets();

        /**
         * @brief   Initialize the actors.
         * @param   cutData: The input cut view's post data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-17
         */
        void generateGraph(Interface::FITKAbstractViewCut* cutData);

        /**
         * @brief   Update the cutter with the value of cutter widget.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-05
         */
        void updateCutFilter();

    private:
        /**
         * @brief   The interactive widget for cutter.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-05
         */
        vtkInteractorObserver* m_cutWidget{ nullptr };

        /**
         * @brief   The interactive slider widget for shpere widget.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        vtkSliderWidget* m_sliderWidget{ nullptr };

        /**
         * @brief   The cutter's callback.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-06
         */
        vtkCutterCallback* m_cutCallback{ nullptr };

        /**
         * @brief   The slider's callback.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        vtkSliderCallback* m_sliderCallback{ nullptr };

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTPOSTCUT_H__
